package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.TestConstant;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityClubNote;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * Created by zlz
 * on  4/8/21
 */
public class VMClub extends ViewModel {

    private MutableLiveData<List<EntityClubNote>> liveNote= new MutableLiveData<>();

    public MutableLiveData<List<EntityClubNote>> getLiveNote() {
        return liveNote;
    }


    public void requestNote(){

        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveNote.setValue(createNotes());
                    }
                });


    }

//<editor-fold defaultState="collapsed" desc="测试">

    private List<EntityClubNote> createNotes(){
        List<EntityClubNote> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {

            EntityClubNote entityClubNote = new EntityClubNote();

            entityClubNote.setFaceUrl(TestConstant.PIC_THREE);
            entityClubNote.setUserFaceUrl(TestConstant.PIC_THREE);
            entityClubNote.setUserName("忘了爱");
            entityClubNote.setTime("10个小时前");
            entityClubNote.setTitle("别哎我,没结果");

            list.add(entityClubNote);

        }

        return list;
        

    }


// </editor-fold>

}
